package admin

import "object/go_cms/models"

type MessageAdminController struct {
	BaseAdminController
	models models.MessageModels
}

//主页
// @router /admin/message/indexUI [get]
func (m *MessageAdminController) IndexUI() {
	m.TplAdmin("message/index")
}

//添加
// @router /admin/message/addUI [get]
func (m *MessageAdminController) AddUI() {
	m.TplAdmin("message/add")
}

// @router /admin/message/editUI [get]
func (m *MessageAdminController) EditUI() {
	m.TplAdmin("message/edit")
}

// @router /admin/message/get [get,post]
func (m *MessageAdminController) Get() {
	mid, _ := m.GetInt64("message_id")
	m.Res.Data, _ = m.models.Get(mid)
	m.Res.Code = 1
	m.Json(m.Res)
}

// @router /admin/message/query [get,post]
func (m *MessageAdminController) Query() {
	maps := m.GetParamMap()
	m.Res.Data, m.Res.Count = m.models.QueryByPage(maps)
	m.Json(m.Res)
}

// @router /admin/message/add [post]
func (m *MessageAdminController) Add() {

}

// @router /admin/message/edit [post]
func (m *MessageAdminController) Edit() {
	maps := m.GetParamMap()
	_, err := m.models.Update(maps)
	if err != nil {
		m.Res.Code = 0
		m.Res.Msg = err.Error()
	} else {
		m.Res.Code = 1
		m.Res.Msg = "保存成功"
	}
	m.Json(m.Res)
}

// @router /admin/message/delete [post]
func (m *MessageAdminController) Delete() {
	id, _ := m.GetInt64("id")
	_, err := m.models.Delete(id)
	if err != nil {
		m.Res.Code = 0
		m.Res.Msg = err.Error()
	} else {
		m.Res.Code = 1
		m.Res.Msg = "删除成功"
	}
	m.Json(m.Res)
}
